home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / sprtxtrn.sea / Support Tools eXternals 1.2.5 / card_15794.txt < prev    next >
Text File  |  1990-11-13  |  9KB  |  257 lines

  1. -- card: 15794 from stack: in.5
  2. -- bmap block id: 16194
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: CurrAppPath
  6. ----- HyperTalk script -----
  7. on HideObjects
  8.   hide cd btn "Try It!"
  9. end HideObjects
  10.  
  11. on ShowObjects
  12.   show cd btn "Try It!"
  13. end ShowObjects
  14.  
  15.  
  16. -- part 1 (button)
  17. -- low flags: 00
  18. -- high flags: A002
  19. -- rect: left=82 top=185 right=219 bottom=175
  20. -- title width / last selected line: 0
  21. -- icon id / first selected line: 0 / 0
  22. -- text alignment: 1
  23. -- font id: 0
  24. -- text size: 12
  25. -- style flags: 8192
  26. -- line height: 16
  27. -- part name: Try it!
  28. ----- HyperTalk script -----
  29. on mouseUp
  30.   global errGlobal
  31.   put HCPath("noDialog:errGlobal") into thePath
  32.   if errGlobal Γëá empty then
  33.     answer "Error: ΓÇ£" & errGlobal & "ΓÇ¥"
  34.     put empty into errGlobal
  35.   else
  36.     answer "This copy of HyperCard is located: ΓÇ£" & thePath & "ΓÇ¥"
  37.   end if
  38. end mouseUp
  39.  
  40.  
  41.  
  42.  
  43. -- part contents for background part 38
  44. ----- text -----
  45. 8/50
  46.  
  47. -- part contents for background part 20
  48. ----- text -----
  49. CurrAppPath - This XFCN returns the full path name of the current application - HyperCard in the case of this stack.   When running under Mac OS the correct path is reported even when you move the application around between calls to the XFCN.  Under A/UX 2.0 this is not always the case.  It occasionally seems to take a while for the file manager to be informed that a file has moved.  
  50. Will this cause you trouble?  Only if you launch an application, go to the finder or CommandShell, move the application, and then quickly go back and call the XFCN.  Even then you will just get the old path, not the end of the world?
  51.  
  52. CurrAppPath( ┬½"noDialog:"errorGlobal┬╗)
  53.  
  54.  
  55.  
  56.  
  57.  
  58. -- part contents for background part 42
  59. ----- text -----
  60. { CurrAppPath(<ΓÇ£noDialogΓÇ¥:errorGlobal>)                  }
  61. { XFCN returns fullpath to the current application   }
  62. {}
  63. {  brought to you by:  Anup Murarka      Eric Carlson    }
  64. {            ALINK:  SKEPTIC      ALINK:  cyNic  }
  65. {                  CIS:  76004,3356    }
  66. {}
  67. {        We are part of the Support Tools Development Group,  }
  68. {        Apple Computer, Inc.   }
  69. {}
  70. {        please DO NOT contack Mac DTS for support of this code!  }
  71. {}
  72. {        please DO contact the authors for support of this code!  }
  73. {}
  74. {        Send comments, bug reports, requests to any of the above  }
  75. {        E-mail addresses or to:}
  76. {}
  77. {              (one of us)          }
  78. {              Apple Computer, Inc.     }
  79. {              900 E. Hamilton, Ave.    }
  80. {              Campbell, CA   95008    }
  81. {              M/S 72-L          }
  82. {}
  83. {  Copyright:  ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.  }
  84. {}
  85. { written by Eric Carlson                    }
  86. { AppleLink:  cyNic                        }
  87. { modification history                      }
  88. {       Date        Initials                  Comments              }
  89. {       ----        ------  ------------------------------------------------------}
  90. {    7/23/90      ec       first written                            }
  91. {    8/28/90      ec/akm  removed code which disposed handle returned from       }
  92. {                    GetAppParms (NOT a good thing to do!), was causing occasional}
  93. {                    crashes.  set FP.ioVRefNum INSIDE of loop so can look past   }
  94. {                    default volume.  }
  95. {}
  96.  
  97. unit CurrAppPath;
  98.  
  99. interface
  100.  
  101.   uses
  102.     HyperXCMD;
  103.  
  104.   procedure MAIN (paramPtr: XCmdPtr);
  105.  
  106. implementation
  107.   procedure reportToUser (paramPtr: XCmdPtr;
  108.                   msgStr: str255);
  109. {}
  110. { report something back to the user.  }
  111. { the last parameter (optional) to an external may contain }
  112.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  113.  { of a HyperTalk global variable into which error messages will be }
  114.  { placed.  we've decided to use this approach to avoid confusing }
  115. { an error message with a valid result being returned from an XFCN. }
  116. {}
  117.     var
  118.       tempStr: str255;
  119.   begin
  120. {check the last param to see if the user requested that}
  121. { we suppress the error dialog }
  122.     ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  123.     UprString(tempStr, true);
  124.     if pos('NODIALOG', tempStr) = 0 then
  125.   { no special error handling specified, throw up a dialog and return the error message }
  126.       begin
  127.         SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  128.         paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  129.       end
  130.     else if (pos(':', tempStr) > 0) then
  131.   { requested global AND noDialog so we fill in the global and return empty }
  132.       begin
  133.         tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  134.                             { get the name of the HC global  to fill }
  135.         SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  136.                             { and fill it }
  137.         paramPtr^.returnValue := PasToZero(paramPtr, '');  { return empty }
  138.       end
  139.     else
  140.   { requested noDialog only so we return the error condition as the result }
  141.       paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  142.   end;  { procedure }
  143.  
  144.   function askedForHelp (paramPtr: XCmdPtr;
  145.                   syntaxMsg: Str255;
  146.                   copyRightMsg: Str255): boolean;
  147. {  check to see if the user sent a '?' or a '!' as }
  148. { the only parameter. if so we will respond with }
  149. { the calling syntax or the copyright/version info }
  150. { for this external }
  151. {}
  152.     var
  153.       firstStr: str255;
  154.   begin
  155.     askedForHelp := false;
  156.     if paramPtr^.paramCount = 1 then
  157.       begin
  158.         ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  159.           { what is the first param? }
  160.         if firstStr = '?' then
  161.           begin
  162.             reportToUser(paramPtr, syntaxMsg);
  163.             askedForHelp := true
  164.           end  { asked for help }
  165.         else if firstStr = '!' then
  166.           begin
  167.             reportToUser(paramPtr, copyRightMsg);
  168.             askedForHelp := true
  169.           end;  { asked for copyright info }
  170.       end;  { one parameter passed }
  171.   end;    { function }
  172.  
  173.   function PathNameFromDirID (dirID: longint;
  174.                   vRefnum: integer;
  175.                   var fullPathName: str255): OSErr;
  176. { build up a full path name given a directory id and an vol ref num.  this method isn't reccomended in general (see the }
  177. {  various tech notes, but we use it in HC externals as HC uses exclusively full path names }
  178.     var
  179.       myCPB: CInfoPBRec;
  180.       directoryName: str255;
  181.       err: OSErr;
  182.   begin
  183.     fullPathName := '';
  184.     with myCPB do
  185.       begin
  186.         ioNamePtr := @directoryName;
  187.         ioDrParID := DirId;
  188.       end;
  189.  
  190.     repeat
  191.       with myCPB do
  192.         begin
  193.           ioVRefNum := vRefNum;
  194.           ioFDirIndex := -1;
  195.           ioDrDirID := myCPB.ioDrParID;
  196.         end;
  197.       err := PBGetCatInfo(@myCPB, FALSE);
  198.  
  199.       directoryName := concat(directoryName, ':');
  200.  
  201. { pascal strings mustn't be longer than 255 chars, though a path name may, so check }
  202.       if length(directoryName) + length(fullPathName) <= 255 then
  203.         fullPathName := concat(directoryName, fullPathName)
  204.       else
  205.         myCPB.ioDrDirID := fsRtDirID;    { lazy persons way to jump out }
  206.  
  207.     until (myCPB.ioDrDirID = 2);
  208.     PathNameFromDirID := err;
  209.   end;
  210.  
  211.   procedure CurrAppPath (paramPtr: XCmdPtr);
  212.     var
  213.       FP: FCBPBRec;
  214.       fileNdx, HCRefNum: integer;
  215.       filePath, fileName: str255;
  216.       fileErr: OSErr;
  217.       dummyH: handle;
  218.   begin
  219.     if askedForHelp(paramPtr, 'CurrAppPath(<ΓÇ£noDialogΓÇ¥:errorGlobal>)', 'v1.0, ┬⌐ 1990 Apple Computer, Inc.,  by Eric Carlson, ') then
  220.       exit(CurrAppPath);
  221.  
  222.     GetAppParms(fileName, HCRefNum, dummyH);  { find the resource ref num of the current app - HC I assume }
  223.     fileName := '';
  224.  
  225. { now step throught the FCB list looking for HC's entry, the one which matches the  res ref num }
  226.     FP.ioCompletion := nil;              { don't want async }
  227.     FP.ioNamePtr := @fileName;          { the file name }
  228.     FP.ioFCBIndx := 0;                { start with the first file }
  229.     repeat
  230.   { loop through all files}
  231.       FP.ioVRefNum := 0;              { report all files on every volume, but this field is refilled by each}
  232.                             { PBGetΓǪ call so reset it each time}
  233.       FP.ioFCBIndx := FP.ioFCBIndx + 1;      { go to the next file }
  234.       fileErr := PBGetFCBInfo(@FP, false);
  235.     until ((fileErr <> noErr) or (FP.ioRefNum = HCRefNum));
  236.  
  237.     filePath := '';                    { nothing yet }
  238.     if ((fileErr = noErr) and (FP.ioRefNum = HCRefNum)) then      { found the culprit! }
  239.       begin
  240.         fileErr := PathNameFromDirID(FP.ioFCBParID, FP.ioVRefNum, filePath);  { build the path }
  241.         if fileErr = noErr then
  242.           filePath := concat(filePath, fileName)  { add it to the file name }
  243.       end;
  244.  
  245.     if filePath <> '' then                            { find the name? }
  246.       paramPtr^.returnValue := PasToZero(paramPtr, filePath)      { return it }
  247.     else
  248.       ReportToUser(paramPtr, 'Unexpected error.');            { something wrongΓǪ }
  249.  
  250.   end;      { procedure CurrAppPath }
  251.  
  252.   procedure MAIN (paramPtr: XCmdPtr);
  253.   begin
  254.     CurrAppPath(paramPtr);
  255.   end;
  256.  
  257. end.  { unit OpenFiles}